// Copyright 2011, Vanya Davidenko.
// Кодировка файла: UTF-8. 
package info.iu9.red;



abstract class AbstractCommandStateVisitor implements StateVisitor {
  public abstract void visit(final MatchState s);
  public abstract void visit(final BeginSaveState s);
  public abstract void visit(final EndSaveState s);

  protected abstract boolean matched();
  protected abstract void addToResult();
  protected abstract void newThread(final int new_state_id_offset);
  protected abstract void move(final int next_state_id_offset);


  public void setStringIterator(final StringIterator string_iterator) {
    string_iterator_ = string_iterator;
  }


  protected void inc() {
    move(1);
  }
  protected void incIf(final boolean condition) {
    if ( condition ) {
      inc();
    }
  }


  public void visit(final JumpState s) {
    move(s.next());
  }
  public void visit(final ForkState s) {
    newThread(s.next_low());
    move(s.next());
  }


  public void visit(final BeginningAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final EndOfStringAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final EndingAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final ReverseEndingAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final StringBeginningAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final StringEndingAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final MultiLineBeginningAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final MultiLineEndingAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final WordBoundaryAnchorState s) {
    incIf(s.check(string_iterator_));
  }
  public void visit(final InvertedWordBoundaryAnchorState s) {
    incIf(s.check(string_iterator_));
  }


  public void visit(final DotState s) {
    addToResult();
  }
  public void visit(final DotAllState s) {
    addToResult();
  }
  public void visit(final CharacterState s) {
    addToResult();
  }
  public void visit(final CaseCharacterState s) {
    addToResult();
  }
  public void visit(final CharacterGroupState s) {
    addToResult();
  }
  public void visit(final CaseCharacterGroupState s) {
    addToResult();
  }


  private StringIterator string_iterator_;
}
